<?php
#[域名语言绑定]
$sysnav = "system";

#[判断权限]
if($_SESSION["admin"]["typer"] != "system")
{
	Error("对不起，您没有权限操作当前功能",$mainlink."?file=index");
}
#[模板管理]
$sql = "SELECT * FROM ".$prefix."tpl";
$tplist = $DB->qgGetAll($sql);

if($sys_act == "add")
{
	Foot("tpldomain.set.qg");
}
elseif($sys_act == "modify")
{
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$mainlink."?file=tpl");
	}
	$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."tpl_domain WHERE id='".$id."'");
	if(!$rs)
	{
		Error("没有找到相关域名信息",$mainlink."?file=tpldomain");
	}
	Foot("tpldomain.set.qg");
}
elseif($sys_act == "setok")
{
	$tplid = intval($tplid);
	$domain = SafeHtml($domain);
	
	#[清除头部http://以及尾部/]
	$domain = str_replace(array("http://"),array(""),$domain);
	$doarr = explode("/", $domain);
	if($doarr[count($doarr)-1]=="")
	{
		$domain = substr($domain,0,strlen($domain)-1);
	}
	
	if(!$domain)
	{
		Error("域名不允许为空",$mainlink."?file=tpldomain");
	}
	$sql = "SELECT * FROM ".$prefix."tpl_domain WHERE domain='".$domain."'";
	$id = intval($id);
	if($id)
	{
		$sql .= " AND id!='".$id."'";
	}
	$check =  $DB->qgGetOne($sql);
	if($check)
	{
		Error("该域名已存在",$mainlink."?file=tpldomain");
	}
	if($id)
	{
		$sql = "UPDATE ".$prefix."tpl_domain SET tplid='".$tplid."',domain='".$domain."' WHERE id='".$id."'";
		$DB->qgQuery($sql);
		Error("域名信息更新成功",$mainlink."?file=tpldomain");
	}
	else
	{
		$sql = "INSERT INTO ".$prefix."tpl_domain(tplid,domain) VALUES('".$tplid."','".$domain."')";
		$DB->qgQuery($sql);
		Error("添加成功！",$mainlink."?file=tpldomain");
	}
}
elseif($sys_act == "delete")
{
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$mainlink."?file=tpldomain");
	}
	$sql = "DELETE FROM ".$prefix."tpl_domain WHERE id='".$id."'";
	$DB->qgQuery($sql);
	Error("域名绑定已解除！",$mainlink."?file=tpldomain");
}
else
{
	if($tplist)
	{
		foreach($tplist AS $key=>$value)
		{
			$sql = "SELECT * FROM ".$prefix."tpl_domain WHERE tplid='".$value["id"]."' ORDER BY id ASC";
			$value["domain"] = $DB->qgGetAll($sql);
			$rslist[] = $value;
		}
	}
	Foot("tpldomain.list.qg");
}
?>
